<?php

function thumbnail($URI,$id){
	$id = explode(".", $id);
	// grab first part of filename
	$id = $id[0];
	$url = "thumbnails/".$id."-thumbnail.jpg";
	$URI = "http://" . $_SERVER['SERVER_NAME'] . "/webapps/iphotos/photo.html?URI=" . urlencode($URI);
	echo $URI;
	
	if(!file_exists($url)){
		$src_img = imagecreatefromjpeg($URI);
		if($src_img){
			$old_x=imageSX($src_img);
			$old_y=imageSY($src_img);
			if ($old_x > $old_y) {
				$thumb_w=100;
				$thumb_h=$old_y*(100/$old_x);
			}
			if ($old_x < $old_y) {
				$thumb_w=$old_x*(100/$old_y);
				$thumb_h=100;
			}
			if ($old_x == $old_y) {
				$thumb_w=100;
				$thumb_h=100;
			}
			$dst_img=ImageCreateTrueColor($thumb_w,$thumb_h);
			imagecopyresampled($dst_img,$src_img,0,0,0,0,$thumb_w,$thumb_h,$old_x,$old_y);
			imagejpeg($dst_img, $url, 100);
		}
	}
}

?>
